package com.atguigu.day22.tcpsocket.s3;

import java.io.IOException;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class Server3 {
    public static void main(String[] args) {
        System.out.println("--------Server3-----------");
        //1.创建服务端对象
        try (ServerSocket serverSocket = new ServerSocket(8989);

             //2.获取连接的客户端对象
             Socket socket = serverSocket.accept();
             //3.准备流对象
             //读取数据
             Scanner sc = new Scanner(socket.getInputStream());
             //写出数据
             PrintStream ps = new PrintStream(socket.getOutputStream());
        ) {
            //3.循环 读 写
            while (true){
                //3.1 读取数据
                String s = sc.nextLine();
                //3.2 进行反转
                StringBuffer reverse = new StringBuffer(s).reverse();
                System.out.println("客户端发来的信息是:"+s+" ,反转后:"+reverse);
                //3.3 反馈
                ps.println(reverse.toString());
            }


        } catch (IOException e) {
            throw new RuntimeException(e);
        }




    }
}
